package logic

import (
	"context"
	"user_svc/internal/svc"
	"user_svc/models/mysql"
	"user_svc/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type PositionUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPositionUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PositionUpdateLogic {
	return &PositionUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PositionUpdateLogic) PositionUpdate(in *user.PositionUpdateRequest) (*user.PositionUpdateResponse, error) {
	// todo: add your logic here and delete this line

	var position mysql.Position
	mysql.DB.Debug().Where("id = ?", in.Id).Find(&position)

	return &user.PositionUpdateResponse{
		Name:    position.Name,
		Types:   position.Types,
		Address: position.Address,
		Price:   float32(position.Price),
		Desc:    position.Desc,
	}, nil
}
